<?php


namespace App\Model;


/**
 * 文章模型类
 *  作者 薛原
 *  日期 2025/10/17
 * Class Articles
 * @package App\Model
 */
class Articles extends Model
{
    protected $table = 'articles';
    protected $fillable = ['user_id','title','slug','content','summary','content_type','cover_image','status','view_count','like_count','comment_count','favorite_count','reading_time'];

    /**
     * 与tag表多对多关联
     * article_tag作为中间表
     * @return \Hyperf\Database\Model\Relations\BelongsToMany
     */
    public function tags()
    {
        return $this->belongsToMany(\App\Model\Tag::class, 'article_tag', 'article_id', 'tag_id');
    }

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(\App\Model\User::class, 'user_id');
    }
}